function query(data){
	$("#tab>tr").remove()
	$.ajax({
		"url":"/query_serial/",
		"data":{"data":JSON.stringify(data)},
		"error":errorAjax,
		"beforeSend":start_load_pic,
		"complete":stop_load_pic,
		"dataType":"jsonp",
		"success":function(data){
			responseCheck(data)
			var tab=document.getElementById("tab")
			for(var i=0;i<data.content.length;i++){
				var tr=document.createElement("tr")

				var td=document.createElement("td")
				var span=document.createElement("span")
				span.className="glyphicon glyphicon-unchecked"
				span.setAttribute("serial",data.content[i].id)
				span.onclick=function(){
					if ($(this).hasClass("glyphicon-unchecked")){
						$(this).removeClass("glyphicon-unchecked").addClass("glyphicon-check")
					}
					else{
						$(this).removeClass("glyphicon-check").addClass("glyphicon-unchecked")
					}
				}
				
				td.appendChild(span)
				tr.appendChild(td)

				var td=document.createElement("td")
				td.textContent=data.content[i].serial_type
				tr.appendChild(td)

				var td=document.createElement("td")
				td.textContent=data.content[i].serial
				tr.appendChild(td)

				var td=document.createElement("td")
				td.textContent=data.content[i].machine_code
				tr.appendChild(td)

				var td=document.createElement("td")
				td.textContent=data.content[i].create_date
				tr.appendChild(td)

				var td=document.createElement("td")
				td.textContent=data.content[i].valid_date
				tr.appendChild(td)

				var td=document.createElement("td")
				td.textContent=data.content[i].valid_date2
				tr.appendChild(td)

				var td=document.createElement("td")
				td.textContent=data.content[i].active_date
				tr.appendChild(td)

				var td=document.createElement("td")
				td.textContent=data.content[i].use_date
				tr.appendChild(td)

				var td=document.createElement("td")
				td.textContent=data.content[i].use_date2
				tr.appendChild(td)

				var td=document.createElement("td")
				td.textContent=data.content[i].address
				tr.appendChild(td)

				tab.appendChild(tr)
			}
		}
	})
}
document.getElementById("query").onclick=function(){
	var data={}
	data.valid_date=$("#valid_date").val()
	data.active=$("#active").val()
	data.use_date=$("#use_date").val()
	data.serial=$("#serial").val()
	if(data.serial.length!==16 && data.serial.length>0){
		showErrorInfo("序列号长度不正确！")
		return false;
	}
	else if(data.serial.length===16){
		query(data)
		return true
	}
	delete data.serial

	data.address=$("#address").val()
	if(data.address.length>0){
		query(data)
		return true
	}
	delete data.address
	data.start_time=$("#start_date").val()
	data.end_time=$("#end_date").val()
	if(data.start_time.length>0 && data.end_time.length>0){
		data.start_time+= " 00:00:00"
		data.end_time+= " 00:00:00"
		query(data)
		return true
	}
	else if(data.start_time.length>0 && data.end_time.length===0){
		data.start_time+= " 00:00:00"
		query(data)
		return true
	}
	else if(data.start_time.length===0 && data.end_time.length>0){
		data.end_time+= " 00:00:00"
		query(data)
		return true
	}
	showErrorInfo("请正确填写查询条件！")
	return false;
	
}
document.getElementById("selectAll").onclick=function(){
	if($(this).hasClass("glyphicon-unchecked")){
		$(this).removeClass("glyphicon-unchecked").addClass("glyphicon-check")
		$("#tab span").removeClass("glyphicon-unchecked").addClass("glyphicon-check")
	}
	else{
		$(this).removeClass("glyphicon-check").addClass("glyphicon-unchecked")
		$("#tab span").removeClass("glyphicon-check").addClass("glyphicon-unchecked")
	}
}
document.getElementById("del").onclick=function(){
	var data=[]
	$("#tab .glyphicon-check").each(function(){
		var serial=this.getAttribute("serial")
		data.push(serial)
	})
	if(data.length===0){
		showErrorInfo("当前无数据被选中！")
		return false;
	}
	data=JSON.stringify(data)
	$.ajax({
		"url":"/query_serial/",
		"type":"DELETE",
		"error":errorAjax,
		"beforeSend":start_load_pic,
		"complete":stop_load_pic,
		"data":{"data":data},
		"success":function(data){
			responseCheck(data)
			showSuccessNotice()
			location.reload()
		}
	})
}
document.getElementById("reset").onclick=function(){
	t=confirm("您真的要这样做吗？")
	if(t===false){
		return false;
	}
	var data=[]
	$("#tab .glyphicon-check").each(function(){
		var serial=this.getAttribute("serial")
		data.push(serial)
	})
	if(data.length===0){
		showErrorInfo("当前无数据被选中！")
		return false;
	}
	data=JSON.stringify(data)
	$.ajax({
		"url":"/reset_serial/",
		"type":"POST",
		"error":errorAjax,
		"beforeSend":start_load_pic,
		"complete":stop_load_pic,
		"data":{"data":data},
		"success":function(data){
			responseCheck(data)
			alert("操作成功")
			location.reload()
		}
	})
}
